import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:miracle_recorder/bloc/auth/auth_bloc.dart';
import 'package:miracle_recorder/bloc/auth/auth_event.dart';
import 'package:miracle_recorder/screens/home/home_screen.dart';
import 'package:miracle_recorder/screens/livestream/livestream_screen.dart';
import 'package:miracle_recorder/screens/profile/profile_screen.dart';
import 'package:miracle_recorder/screens/topic/topic_screen.dart';
import 'package:miracle_recorder/theme/app_theme.dart';

class MainScreen extends StatefulWidget {
  const MainScreen({super.key});

  @override
  State<MainScreen> createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  int _currentIndex = 0;
  
  final List<Widget> _screens = [
    const HomeScreen(),
    const TopicScreen(),
    const LivestreamScreen(),
    const ProfileScreen(),
  ];
  
  final List<String> _titles = [
    '首页',
    '话题',
    '直播',
    '我的',
  ];
  
  final List<IconData> _icons = [
    Icons.home_outlined,
    Icons.topic_outlined,
    Icons.live_tv_outlined,
    Icons.person_outline,
  ];
  
  final List<IconData> _selectedIcons = [
    Icons.home,
    Icons.topic,
    Icons.live_tv,
    Icons.person,
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: _screens,
      ),
      bottomNavigationBar: Container(
        decoration: BoxDecoration(
          color: Theme.of(context).bottomNavigationBarTheme.backgroundColor,
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.1),
              blurRadius: 8,
              offset: const Offset(0, -2),
            ),
          ],
        ),
        child: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: (index) {
            setState(() {
              _currentIndex = index;
            });
          },
          type: BottomNavigationBarType.fixed,
          items: List.generate(_titles.length, (index) {
            return BottomNavigationBarItem(
              icon: Icon(
                _icons[index],
                size: 24,
              ),
              activeIcon: Icon(
                _selectedIcons[index],
                size: 24,
              ),
              label: _titles[index],
            );
          }),
        ),
      ),
    );
  }
}